﻿// Project: Salient
// http://salient.codeplex.com
// 
// Copyright 2010, Sky Sanders <sky at skysanders.net>
// licensed under the GPL Version 2 licenses.
// http://salient.codeplex.com/license
// 
// 
// You may use this code under the terms of the GNU General Public 
// License (GPL) Version 2.
using System;

namespace Salient.Net
{
    /// <summary>
    ///   This is a thread-safe class that will cache requests for a configurable interval according to user definable rules.
    /// </summary>
    public interface IGatewayCache
    {
        /// <summary>
        /// The default period of time to cache requests. Default is 1 minute.
        /// </summary>
        TimeSpan DefaultCacheDuration { get; set; }

        /// <summary>
        ///   Retrieve a cached object, if it exists, otherwise null.
        /// </summary>
        /// <param name = "url"></param>
        /// <returns></returns>
        object Get(string url);

        /// <summary>
        ///   Retrieve a strongly typed cached object, if it exists, otherwise null.
        /// </summary>
        /// <typeparam name = "T"></typeparam>
        /// <param name = "url"></param>
        /// <returns></returns>
        T Get<T>(string url);

        /// <summary>
        ///   Sets/Replaces an object in the cache and resets the scavenge time according to the rule specified.
        ///   If the rule does not exist, the default cache duration is applied
        /// </summary>
        /// <param name = "url"></param>
        /// <param name = "rule"></param>
        /// <param name = "data"></param>
        void Set(string url, string rule, object data);

        /// <summary>
        ///   Removes a cached item
        /// </summary>
        /// <param name = "url"></param>
        void Remove(string url);

        /// <summary>
        ///   Clears all cached items
        /// </summary>
        void Clear();

        /// <summary>
        ///   Sets a cache rule keyed on the string rule.
        /// </summary>
        /// <param name = "rule"></param>
        /// <param name = "duration"></param>
        void SetRule(string rule, TimeSpan duration);
    }
}
